package sicnu.cs.ich.api.domain.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * 记录非遗对象
 *
 * @author CaiKe
 * @date 2021/11/7 19:48
 */
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
public class IchHitDTO extends BaseHitComparator<IchHitDTO> implements Serializable {

    private static final long serialVersionUID = -6415840348589680892L;
    /**
     * 非遗id
     */
    private Integer id;
    private String name;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setHit(Integer hit) {
        this.hit = hit;
    }

    /**
     * 热度
     */
    @JsonIgnoreProperties(ignoreUnknown = true)
    private Integer hit;

    public IchHitDTO() {
    }

    public IchHitDTO(Integer id, Integer hit) {
        this.id = id;
        this.hit = hit;
    }

    public IchHitDTO(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    /**
     * 获取当前类用于Hash的键
     *
     * @return 键
     */
    @Override
    @JsonIgnore
    public int getKey() {
        return this.id;
    }

    /**
     * 获取热度
     */
    @Override
    public int getHit() {
        return this.hit;
    }

    @Override
    public String toString() {
        return "IchHitDTO{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", hit=" + hit +
                '}';
    }

    /**
     * 通过id和热度构造该对象
     */
    @Override
    public IchHitDTO build(int key, int hit) {
        return new IchHitDTO(key, hit);
    }

    @Override
    public int compareTo(IchHitDTO ichHitDTO) {
        return Double.compare(this.hit, ichHitDTO.hit);
    }
}